#include<vector>

using namespace std;

class Solution {
public:
    int maxProfit(vector<int> &prices) {
        int lowest = INT_MAX;
        int maxProfit = 0;
        for (int i = 0; i < prices.size(); ++i) {
            if (prices[i] < lowest)lowest = prices[i];
            else if (prices[i] - lowest > maxProfit) maxProfit = prices[i] - lowest;
        }
        return maxProfit;
    }
};